<?php

namespace App\Base\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use App\Base\Exceptions\ApiException;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function throwValidatorException($validator)
    {
        $error = $validator->errors()->getMessages();
        foreach ($error as $k => $v) {
            $error = $v;
            throw  new ApiException([422,$error[0]]);
            break;
        }
        //throw  new ApiException(ApiException::ERROR_VALIDATION);
    }

    public function show_error($msg)
    {
        return view("common.error")->with("msg", $msg);
    }
}
